var utils = require('../util.js');
var app = getApp();

//通用接口  
var ModuleAll = {};
//获取详情
ModuleAll.getParameterValue = utils.request1("d", "getParameterValue.json")
//获取积分规则
ModuleAll.getArticleSimpleDetail = utils.request1("d","getArticleSimpleDetail.json")
//新增发票
ModuleAll.submitOneMemberInvoiceDefine = utils.request1("ds","submitOneMemberInvoiceDefine.json")
//获取会员发票定义列表
ModuleAll.getMemberInvoiceDefineList = utils.request1("ds","getMemberInvoiceDefineList.json")
//获取发票列表
ModuleAll.getInvoiceList = utils.request1("ds","getInvoiceList.json")
//编辑一个发票
ModuleAll.updateMemberInvoiceDefine = utils.request1("ds","updateMemberInvoiceDefine.json")
//获取发票详情信息
ModuleAll.getMemberInvoiceDefineDetail = utils.request1("ds","getMemberInvoiceDefineDetail.json")
//删除一条发票
ModuleAll.deleteOneMemberInvoiceDefine = utils.request1("ds","deleteOneMemberInvoiceDefine.json")

ModuleAll.PullDownRefresh = function (that, fun, ffn) {
  setTimeout(() => {
    wx.stopPullDownRefresh();
  }, 750)

  wx.showLoading({
    title: '加载中',
    mask: true
  })
  that.setData({
    showAjaxLoad: false,
    showAjaxNomore: false,
    currentPage: 1
  })
  if (fun) fun()
  setTimeout(function () {
    wx.hideLoading()
  }, 1000)
}

//上拉加载 
ModuleAll.ReachBottom = function (name, that, fun, ffn) {
  name = name + "Page"
  var page = that.data[name];
  name = name + ".currentPage"
  if (page.hasNextPage) {
    var currentPage = page.currentPage ? page.currentPage : 1;
    currentPage++;
    that.setData({
      showAjaxLoad: true,
      [name]: currentPage
    })
    if (fun) fun()
  } else {
    that.setData({
      showAjaxNomore: true
    })
  }

}

//上传文件
ModuleAll.uploadFile = function (data, that, fun, ffn) {
  wx.uploadFile({
    url: app.dServerUrl + 'uploadFile.json',
    filePath: data,
    name: 'file',
    dataType: 'json',
    success(res) {
      if (res.data) {
        res.data = JSON.parse(res.data)
      }
      if (fun) fun(res)
    },
    fail(err) {
      if (ffn) ffn(err)
    }
  })
}


module.exports = ModuleAll